(()=>{
	function loadPage(n=1){
	var params=location.search.slice(1)+"&pno="+n;
	$.get("data/goWhere.php",params)
		.then(data=>{
			var html="";
			for(var p of data.data){
				html+=`
					<a href="#" class="show">
                <div class="img-box">
                    <img class="img" src="${p.pic}" alt=""> 
                </div>
                <h2 class="tit">${p.title}</h2>
                <h3 class="des">${p.detail}</h3>
            </a>
				`;
			}
			$("#container>.first").html(html);
			var html="";
			for(var i=1;i<=data.pageCount;i++){
				html+='<a href="javascript:;" class="pageItem">'+i+'</a>';
			}
			$(".page>.pageCount").html(
				'<a href="javascript:;" class="prev">上一页</a>' 
				+html+
				'<a href="javascript:;" class="next">下一页</a>'
			);

			$(".page>.pageCount>a:eq("+n+")").addClass("active");
			if(n==1){
				$(".page>.pageCount>a:first-child").addClass("disabled");
			}
			if(n==data.pageCount){
					$(".page>.pageCount>a:last-child").addClass("disabled");
			}
			if(n!=1&&n!=data.pageCount){
				$(".page>.pageCount>a:last-child,.page>.pageCount>a:last-child").removeClass("disabled");
			}
		})
	}
		loadPage();
		$(".page>.pageCount").on("click","a:not(.disabled):not(.active)",function(e){
			e.preventDefault;
			$a=$(this);
			var n=parseInt($(".page>.pageCount>a.active").html());
				if($a.is(":first-child")){
							loadPage(n-1);
				}
				else if($a.is(":last-child")){
							loadPage(n+1);
				}else{
							loadPage($a.html());
				}
		})

		/*$.ajax({
		type:"GET",
		url:"data/goWhere.php",
		success:function(data){
			console.log(data.data);
			var html="";
			for(var p of data.data){
				html+=`
					<a href="#" class="show">
						<div class="imgShow"><img src="${p.pic}" alt=""></div>
						<div class="word">
							<h2>${p.title}</h2>
							<h3>${p.detail}</h3>
						</div>
            		</a>
				`;
			}
			$("#container>.first").html(html);
			var html="";
				for(var i=1;i<=data.pageCount;i++){
					html+='<a href="javascript:;">'+i+'</a>';
				}
				$(".page").html(
					'<a href="javascript:;" class="previous">上一页</a>' 
					+html+
					'<a href="javascript:;" class="next">下一页</a>'
				);
		},
		error:function(){
			alert("网络故障");
		}
	})*/
})()
//(()=>{
//	
//})()